<template>
  <div>
     <div class="title">
       <p class="iconfont icon-bg-left"></p>
       <p>光与影</p>
       <p class="iconfont icon-shenglvehao"></p>
     </div>
    <div class="search">
       <p class="iconfont icon-sousuo"></p>
       <input type="text" @click="handleSerch" placeholder="釜山行,夏有乔木仰望天堂">
    </div>
    <div class="nav">
      <p>正在热映</p>
       <p @click="handleTop250">更多 ></p>
    </div>
    <Item :data="top250"></Item>

       <div class="nav">
      <p>即将上映</p>
       <p @click="handleinTheaters">更多 ></p>
    </div>
    <Item :data="inTheaters"></Item>


       <div class="nav"> 
      <p>主播电台</p>
       <p @click="handlecomingSoon">更多 ></p>
    </div>
    <Item :data="comingSoon"></Item>
  </div>
</template>

<script>
import Item from './components/Item.vue'
export default {
     data(){
       return{
         top250:[],
         inTheaters:[],
         comingSoon:[]
       }
     },
     components:{
       Item
     },
     mounted(){
       this.$http('http://47.108.197.28:4000/api/movie/top250').then(res=>{
        res.data.res.slice(0,3).forEach(item => {
            item.count=this.getArrayStr(item.rating)
        });
        this.top250=res.data.res.slice(0,3)
       })
   this.$http('http://47.108.197.28:4000/api/movie/inTheaters').then(res=>{
        res.data.res.slice(0,3).forEach(item => {
            item.count=this.getArrayStr(item.raiting)
        });
        this.inTheaters=res.data.res.slice(0,3)
       })
          this.$http('http://47.108.197.28:4000/api/movie/comingSoon').then(res=>{
        res.data.res.slice(0,3).forEach(item => {
            item.count=this.getArrayStr(item.rating)
        });
        this.comingSoon=res.data.res.slice(0,3)
       })
     
     },
     methods:{
       getArrayStr(sum){
         var arr=[]
         for(var i=0;i<5;i++){
            
             if(sum>2){
               arr.push(2)
             }else if(sum>0){
               arr.push(Math.round(sum*10)/10)
             }else{
               arr.push(0)
             }
              sum=sum-2
         }
         return arr
       },
       handleSerch(){
         this.$router.push('/movieSearch')
       },
       handleTop250(){
              var url='http://47.108.197.28:4000/api/movie/top250';
               this.$router.push(`/movieAll?url=${url}`)
       },
        handleinTheaters(){
 var url='http://47.108.197.28:4000/api/movie/inTheaters';
               this.$router.push(`/movieAll?url=${url}`)
        },
         handlecomingSoon(){
           var url='http://47.108.197.28:4000/api/movie/comingSoon';
               this.$router.push(`/movieAll?url=${url}`)
         }
     }
}
</script>

<style scoped>

.nav{
  height: 60px;
  margin-top: 10px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.title{
  height: 70px;
  width: 10rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: rgb(99, 131, 219);
}
.title p{
  font-size: 35px;
  color: white;
}
.search{
    width: 10rem;
  height: 80px;
  background-color: #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.search p{
  width: 15%;
  text-align: center;
  font-size: 45px;
}
input{
  width: 85%;
  height: 100%;
  border: none;
  /* text-decoration: none; */
}
</style>